# Loading required packages
library(lmtest); library(sandwich); library(stargazer)

######################
# AGGREGATE ANALYSES #
######################
# Loading the data
load("analysis_2_aggregate_data.RData")

##############
# FIGURE D.1 #
##############
### Calculating net support for obstruction for each level of intensity and each partisan group ###
# Copartisan
severe.cop <- mean(unlist(aggregate_data[which(aggregate_data$intensity == "Severe"),c("copartisan_net_support")]))
moderate.cop <- mean(unlist(aggregate_data[which(aggregate_data$intensity == "Moderate"),c("copartisan_net_support")]))
weak.cop <- mean(unlist(aggregate_data[which(aggregate_data$intensity == "Weak"),c("copartisan_net_support")]))
# Combining into vector for plotting
copartisans <- c(weak.cop, moderate.cop, severe.cop)

# Independents
severe.ind <- mean(unlist(aggregate_data[which(aggregate_data$intensity == "Severe"),c("independent_net_support")]))
moderate.ind <- mean(unlist(aggregate_data[which(aggregate_data$intensity == "Moderate"),c("independent_net_support")]))
weak.ind <- mean(unlist(aggregate_data[which(aggregate_data$intensity == "Weak"),c("independent_net_support")]))
# Combining into vector for plotting
independents <- c(weak.ind, moderate.ind, severe.ind)

# Outpartisans
severe.out <- mean(unlist(aggregate_data[which(aggregate_data$intensity == "Severe"),c("outpartisan_net_support")]))
moderate.out <- mean(unlist(aggregate_data[which(aggregate_data$intensity == "Moderate"),c("outpartisan_net_support")]))
weak.out <- mean(unlist(aggregate_data[which(aggregate_data$intensity == "Weak"),c("outpartisan_net_support")]))
# Combining into vector for plotting
outpartisans <- c(weak.out, moderate.out, severe.out)

# Formal t-tests of difference between strong and weak forms of obstruction for each partisan alignment group
# Copartisans net support, difference of 8.6, p= 0.1827
round((weak.cop-severe.cop),1)
t.test(unlist(aggregate_data[which(aggregate_data$intensity == "Severe"),c("copartisan_net_support")]),
       unlist(aggregate_data[which(aggregate_data$intensity == "Weak"),c("copartisan_net_support")]))
# Independents net support, difference of 31.8, p= 0.001951
round((weak.ind-severe.ind),1)
t.test(unlist(aggregate_data[which(aggregate_data$intensity == "Severe"),c("independent_net_support")]),
       unlist(aggregate_data[which(aggregate_data$intensity == "Weak"),c("independent_net_support")]))
# Outpartisans net support, difference of 40.4, p= 0.01552
round((weak.out-severe.out),1)
t.test(unlist(aggregate_data[which(aggregate_data$intensity == "Severe"),c("outpartisan_net_support")]),
       unlist(aggregate_data[which(aggregate_data$intensity == "Weak"),c("outpartisan_net_support")]))

group <- c(0.5,1.55,2.55)
par(mar=c(4.5,5,1,1), mgp=c(2,.25,0))
plot(group,independents,xlim=c(0,3),ylim=c(-60,60), tck=0, cex.main=1, main="", cex.lab=1, cex.axis=1, 
     pch=24, cex=1.5, ylab="Net Support for Obstruction", xaxt="n", yaxt="n", xlab="Intensity of Obstruction", type="b", lwd=1.5)
abline(h=0)
axis(2,at=seq(-60,60,by=10), cex.axis=1, 
     labels=c("-60","-50","-40","-30","-20","-10","0","10","20","30","40","50","60"), tck=0.01, las=1)
axis(1, at=c(0.5,1.5,2.5),cex.axis=0.9,labels=c("Weak","Moderate","Severe"))
lines(x=c(0.5,1.5,2.5), y=copartisans, pch=16, type="b", lty=2, lwd=1.5, cex=1.5)
lines(x=c(0.5,1.5,2.5), y=outpartisans, pch=15, col="grey60", type="b", lty=3, lwd=1.5, cex=1.5)
text(x=2, y=45, "Outpartisans (40.4, p<0.02)", cex=.8)
text(x=2, y=-43, "Copartisans (8.6, p<0.19)", cex=.8)
text(x=1.5, y=8, "Independents (31.8, p<0.01)", cex=.8)

##############
# FIGURE D.2 #
##############
# Subsetting data to polls with data on support for nominee as well as obstruction
aggregate_data_with_nominee <- aggregate_data[which(!is.na(aggregate_data$copartisan_proportion_oppose_nominee)),]

### Calculating net opposition to nominee for each level of intensity and each partisan group ###
# Copartisan
severe.cop.proportion.oppose <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("copartisan_proportion_oppose_nominee")]))
moderate.cop.proportion.oppose <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Moderate"),c("copartisan_proportion_oppose_nominee")]))
weak.cop.proportion.oppose <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("copartisan_proportion_oppose_nominee")]))
# Combining into vector for plotting
copartisans.proportion.oppose <- c(weak.cop.proportion.oppose, moderate.cop.proportion.oppose, severe.cop.proportion.oppose)
copartisans.percentage.oppose <- c(weak.cop.proportion.oppose, moderate.cop.proportion.oppose, severe.cop.proportion.oppose)*100

# Independent
severe.ind.proportion.oppose <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("independent_proportion_oppose_nominee")]))
moderate.ind.proportion.oppose <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Moderate"),c("independent_proportion_oppose_nominee")]))
weak.ind.proportion.oppose <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("independent_proportion_oppose_nominee")]))
# Combining into vector for plotting
independents.proportion.oppose <- c(weak.ind.proportion.oppose, moderate.ind.proportion.oppose, severe.ind.proportion.oppose)
independents.percentage.oppose <- c(weak.ind.proportion.oppose, moderate.ind.proportion.oppose, severe.ind.proportion.oppose)*100

# Outpartisan
severe.out.proportion.oppose <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("outpartisan_proportion_oppose_nominee")]))
moderate.out.proportion.oppose <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Moderate"),c("outpartisan_proportion_oppose_nominee")]))
weak.out.proportion.oppose <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("outpartisan_proportion_oppose_nominee")]))
# Combining into vector for plotting
outpartisans.proportion.oppose <- c(weak.out.proportion.oppose, moderate.out.proportion.oppose, severe.out.proportion.oppose)
outpartisans.percentage.oppose <- c(weak.out.proportion.oppose, moderate.out.proportion.oppose, severe.out.proportion.oppose)*100

### Calculating net support for obstruction for each level of intensity and each partisan group (subset data, so different results than in main analysis) ###
# Copartisan
severe.cop.proportion <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("copartisan_proportion_support")]))
moderate.cop.proportion <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Moderate"),c("copartisan_proportion_support")]))
weak.cop.proportion <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("copartisan_proportion_support")]))
# Combining into vector for plotting
copartisans.proportion <- c(weak.cop.proportion, moderate.cop.proportion, severe.cop.proportion)
copartisans.percentage <- c(weak.cop.proportion, moderate.cop.proportion, severe.cop.proportion)*100

# Independents
severe.ind.proportion <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("independent_proportion_support")]))
moderate.ind.proportion <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Moderate"),c("independent_proportion_support")]))
weak.ind.proportion <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("independent_proportion_support")]))
# Combining into vector for plotting
independents.proportion <- c(weak.ind.proportion, moderate.ind.proportion, severe.ind.proportion)
independents.percentage <- c(weak.ind.proportion, moderate.ind.proportion, severe.ind.proportion)*100

# Outpartisans
severe.out.proportion <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("outpartisan_proportion_support")]))
moderate.out.proportion <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Moderate"),c("outpartisan_proportion_support")]))
weak.out.proportion <- mean(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("outpartisan_proportion_support")]))
# Combining into vector for plotting
outpartisans.proportion <- c(weak.out.proportion, moderate.out.proportion, severe.out.proportion)
outpartisans.percentage <- c(weak.out.proportion, moderate.out.proportion, severe.out.proportion)*100

### Formal t-tests of difference in *support for obstruction* between strong and weak forms of obstruction for each partisan alignment group ###
# Copartisans proportion support, difference of -1.0, p= 0.8586
round((weak.cop.proportion*100)-(severe.cop.proportion*100),1)
t.test(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("copartisan_proportion_support")])*100,
       unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("copartisan_proportion_support")])*100)
# Independents proportion support, difference of 21.5, p= 0.02901
round((weak.ind.proportion*100)-(severe.ind.proportion*100),1)
t.test(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("independent_proportion_support")])*100,
       unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("independent_proportion_support")])*100)
# Outpartisans proportion support, difference of 34.5, p= 0.02486
round((weak.out.proportion*100)-(severe.out.proportion*100),1)
t.test(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("outpartisan_proportion_support")]*100),
       unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("outpartisan_proportion_support")])*100)

### Formal t-tests of difference in *opposition to nominee* between strong and weak forms of obstruction for each partisan alignment group ###
# Copartisans proportion support, difference of -5.3, p= 0.2096
round((weak.cop.proportion.oppose*100)-(severe.cop.proportion.oppose*100),1)
t.test(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("copartisan_proportion_oppose_nominee")])*100,
       unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("copartisan_proportion_oppose_nominee")])*100)
# Independents proportion support, difference of -0.9, p= 0.9288
round((weak.ind.proportion.oppose*100)-(severe.ind.proportion.oppose*100),1)
t.test(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("independent_proportion_oppose_nominee")])*100,
       unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("independent_proportion_oppose_nominee")])*100)
# Outpartisans proportion support, difference of 4.2, p= 0.7488
round((weak.out.proportion.oppose*100)-(severe.out.proportion.oppose*100),1)
t.test(unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Severe"),c("outpartisan_proportion_oppose_nominee")]*100),
       unlist(aggregate_data_with_nominee[which(aggregate_data_with_nominee$intensity == "Weak"),c("outpartisan_proportion_oppose_nominee")])*100)

group <- c(0.5,1.55,2.55)
par(mar=c(4.5,5,1,1), mgp=c(2,.25,0))
plot(group,independents.percentage,xlim=c(0,3),ylim=c(0,100), tck=0, cex.main=1, main="", cex.lab=1.2, cex.axis=1, 
     pch=17, cex=1.5, ylab="Average Percentage of Respondents Who Support Obstruction (Black) 
     or Oppose Nominee (Red)", xaxt="n", yaxt="n", xlab="Intensity of Obstruction", type="b", lwd=1.5)
axis(2,at=seq(0,100,by=10), cex.axis=1, 
     labels=c("0","10","20","30","40","50","60","70","80","90","100"), tck=0.01, las=1)
axis(1, at=c(0.5,1.5,2.5),cex.axis=0.9,labels=c("Weak","Moderate","Severe"))

points(x=c(0.5,1.5,2.5), y=copartisans.percentage.oppose, pch=1, col="red", type="b", lty=2, lwd=1.5, cex=1.5)

points(x=c(0.5,1.5,2.5), y=independents.percentage.oppose, pch=24, col="red", type="b", lty=2, lwd=1.5, cex=1.5)

points(x=c(0.5,1.5,2.5), y=outpartisans.percentage.oppose, pch=0, col="red", type="b", lty=2, lwd=1.5, cex=1.5)

lines(x=c(0.5,1.5,2.5), y=copartisans.percentage, pch=16, type="b", lty=2, lwd=1.5, cex=1.5)
lines(x=c(0.5,1.5,2.5), y=outpartisans.percentage, pch=15, type="b", lty=3, lwd=1.5, cex=1.5)
text(x=2, y=80, "Outpartisans: Obstruction (34.5, p<0.03)", cex=0.8)
text(x=2, y=26, "Copartisans: Obstruction (-1.0, p<0.86)", cex=0.8)
text(x=1.5, y=58, "Independents: Obstruction (21.5, p<0.03)", cex=0.8)

text(x=2, y=77, "Outpartisans: Nominee (4.2, p<0.75)", cex=0.8, col="red")
text(x=2, y=23, "Copartisans: Nominee (-5.3, p<0.21)", cex=0.8, col="red")
text(x=1.5, y=55, "Independents: Nominee (-0.9, p<0.93)", cex=0.8, col="red")

##########################
# SECTION D.4 DISCUSSION #
##########################
### Moderate intensity questions and differences in support for questions with and without individual-level data available ###
# Total number of moderate intensity questions
length(which(aggregate_data$intensity == "Moderate"))
# Total number of moderate intensity questions from surveys with individual-level data
length(which(aggregate_data$intensity == "Moderate" & aggregate_data$individual_level_data == 1))

# Aggregate copartisan support for obstruction from surveys with individual-level data 
round(mean(unlist(aggregate_data[which(aggregate_data$intensity == "Moderate" & aggregate_data$individual_level_data == 1),c("copartisan_proportion_support")])),3)

# Aggregate copartisan support for obstruction from all surveys 
round(mean(unlist(aggregate_data[which(aggregate_data$intensity == "Moderate"),c("copartisan_proportion_support")])),3)

# Aggregate copartisan support for obstruction from surveys without individual-level data  
round(mean(unlist(aggregate_data[which(aggregate_data$intensity == "Moderate" & aggregate_data$individual_level_data == 0),c("copartisan_proportion_support")])),3)

#############################
# INDIVIDUAL-LEVEL ANALYSIS #
#############################
rm(list=ls())

# Loading the dataset of the HH and MC polls
load("analysis_2_individual_surveys.RData")

# Loading the dataset of all the individual surveys from iPoll
# You can generate this dataset with the parse_ipoll_data.R file
# To generate the dataset, you will need access to the Roper iPoll database
# See the instructions in the read_me_jlc_obstruction.txt file or the parse_ipoll_data.R file for more information
load("ipoll_individual_surveys.RData")

# Merging the two datasets together to create the full dataset for the analysis
omnibus_dataset <- rbind(individual_dataset, ipoll_individual_dataset)
rm(individual_dataset, ipoll_individual_dataset)

#############
# TABLE D.3 #
#############
### Running the regressions ###
# Model 1: basic analysis, no covariates, no interaction
omnibus.regression.1 <- lm(support_delay ~ copartisan_of_president + outpartisan_of_president + intensity, data=omnibus_dataset)
summary(omnibus.regression.1)

# Model 2: no covariates, interaction
omnibus.regression.2 <- lm(support_delay ~ copartisan_of_president*intensity + outpartisan_of_president*intensity, data=omnibus_dataset)
summary(omnibus.regression.2)

# Model 3: gender and race covariates (available for all surveys), interaction, president fixed effects
omnibus.regression.3 <- lm(support_delay ~ copartisan_of_president*intensity + outpartisan_of_president*intensity + white + male + president, data=omnibus_dataset)
summary(omnibus.regression.3)

# Putting the models together and into a stargazer table
analysis.2.regression.models <- list(omnibus.regression.1, omnibus.regression.2, omnibus.regression.3)
stargazer(analysis.2.regression.models, digits=2, star.cutoffs=c(0.05), no.space=T,
          covariate.labels = c("Copartisan of President","Outpartisan of President","White","Male","Obama","Trump",
                               "Copartisan of President $\\times$ Moderate Intensity","Copartisan of President $\\times$ Severe Intensity",
                               "Outpartisan of President $\\times$ Moderate Intensity","Outpartisan of President $\\times$ Severe Intensity",
                               "Moderate Intensity","Severe Intensity",
                               "Constant"),
          dep.var.labels = "DV: Support for Delay",
          dep.var.caption = "",
          title="Regression Results: Intensity, Partisanship, and Support for Obstruction",
          label = "regression-version-of-analysis-2",
          keep.stat =  c("n","rsq","f"))

#############
# TABLE D.4 #
#############
### Subsetting to just respondents who answered the February 24-27, 2016 CNN/ORC survey ###
cnn_orc_february_2016_survey <- omnibus_dataset[which(omnibus_dataset$survey == "cnn orc february 2016"),]

# Dropping respondents who don't answer both the severe and moderate questions (their respondent_ID appears just once in the dataset)
cnn_orc_february_2016_survey <- cnn_orc_february_2016_survey[which(cnn_orc_february_2016_survey$respondent_ID %in% names(which(table(cnn_orc_february_2016_survey$respondent_ID) == 2))),]

### Regressions ###
# Within-respondent regression (respondent ID fixed effects)
within.survey.slim <- lm(support_delay ~ intensity + respondent_ID, data = cnn_orc_february_2016_survey)
summary(within.survey.slim)

# Clustering SEs by respondent ID
within.survey.clustered <- coeftest(within.survey.slim, vcov. = vcovCL, cluster = ~respondent_ID)

# Not within-respondent regression
within.survey.slim.not.within <- lm(support_delay ~ copartisan_of_president*intensity + outpartisan_of_president*intensity, data = cnn_orc_february_2016_survey)
summary(within.survey.slim.not.within)

# Clustering SEs
within.survey.clustered.not.within <- coeftest(within.survey.slim.not.within, vcov. = vcovCL, cluster = ~respondent_ID)

# Putting the models together and into a stargazer table
clusterlist <- list(within.survey.clustered.not.within,within.survey.clustered)
stargazer(clusterlist,digits=2, star.cutoffs=c(0.05), no.space=T,
          keep=c("copartisan_of_president","intensity","outpartisan_of_president","Constant"),
          covariate.labels = c("Copartisan of President","Severe Intensity","Outpartisan of President","Copartisan of President $\\times$ Severe Intensity","Outpartisan of President $\\times$ Severe Intensity",
                               "Constant"),
          dep.var.labels = "DV: Support for Delay",
          dep.var.caption = "",
          title="Regression Results: Within-Survey Support for Obstruction",
          label = "within-survey-regression-results",
          keep.stat =  c("n","rsq","f"))

### Average within-person differences for each partisan group ###
# Vector of unique response IDs
unique_response_ids <- unique(cnn_orc_february_2016_survey$respondent_ID)
# Values to save
within_person_difference <- rep(NA, length(unique_response_ids))
copartisan_indicator <- rep(NA, length(unique_response_ids))
outpartisan_indicator <- rep(NA, length(unique_response_ids))

# For each unique respondent
for(i in 1:length(unique_response_ids)){
  # Just that respondent's evaluations
  response.df <- cnn_orc_february_2016_survey[which(cnn_orc_february_2016_survey$respondent_ID == unique_response_ids[i]),]
  # Subtract severe support from moderate support
  difference <- response.df$support_delay[which(response.df$intensity == "moderate")] - response.df$support_delay[which(response.df$intensity == "severe")]
  # Saving the difference for that person
  within_person_difference[i] <- difference
  # Denoting person's copartisanship and outpartisanship with president
  copartisan_indicator[i] <- response.df$copartisan_of_president[1]
  outpartisan_indicator[i] <- response.df$outpartisan_of_president[1]
}

# Overall, 20.4 more support for moderate than severe obstruction
round(mean(within_person_difference, na.rm=T),3)
# Copartisans, -1.9 more support for moderate than severe obstruction
round(mean(within_person_difference[which(copartisan_indicator == 1)], na.rm=T),3)
# Outpartisans, 43.4 more support for moderate than severe obstruction
round(mean(within_person_difference[which(outpartisan_indicator == 1)], na.rm=T),3)
# Independents, 17.5 more support for moderate than severe obstruction
round(mean(within_person_difference[which(copartisan_indicator == 0 & outpartisan_indicator == 0)], na.rm=T),3)

#############
# TABLE D.5 #
#############
# Dropping responses with no measures of support for nominee (of the two measures)
omnibus_dataset_nominee_support <- omnibus_dataset[which((omnibus_dataset$want_the_nominee %in% c(0,1))|(omnibus_dataset$positive_about_the_nominee %in% c(0,1))),]

# Creating overall measure of general support for nominee; for the surveys where both questions were asked, any coding of "1" will be treated as support the nominee
want_nominee <- ifelse(omnibus_dataset_nominee_support$want_the_nominee %in% c(1), 1, 0)
positive_nominee <- ifelse(omnibus_dataset_nominee_support$positive_about_the_nominee %in% c(1), 1, 0)
combined_support <- ifelse(want_nominee == 1 | positive_nominee == 1, 1, 0)

omnibus_dataset_nominee_support$combined_support <- combined_support

# Regression, controlling for support for nominee
omnibus.regression.nominee.support.combined <- lm(support_delay ~ copartisan_of_president*intensity + outpartisan_of_president*intensity + combined_support + white + male + 
                                                    president, data=omnibus_dataset_nominee_support)
summary(omnibus.regression.nominee.support.combined)

# Regression, controlling for support for nominee and interacting it with partisanship 
omnibus.regression.nominee.support.combined.interact.support <- lm(support_delay ~ copartisan_of_president*intensity + outpartisan_of_president*intensity + 
                                                                     combined_support + copartisan_of_president*combined_support + outpartisan_of_president*combined_support + 
                                                                     white + male + president, data=omnibus_dataset_nominee_support)
summary(omnibus.regression.nominee.support.combined.interact.support)

# Putting the results into a stargazer table
control.nominee.support.models <- list(omnibus.regression.nominee.support.combined, omnibus.regression.nominee.support.combined.interact.support)
stargazer(control.nominee.support.models, digits=2, star.cutoffs=c(0.05), no.space=T,
          covariate.labels = c("Copartisan of President","Moderate Intensity","Severe Intensity","Outpartisan of President","Support Nominee","White","Male","Obama","Trump",
                               "Copartisan of President $\\times$ Moderate Intensity","Copartisan of President $\\times$ Severe Intensity",
                               "Outpartisan of President $\\times$ Moderate Intensity","Outpartisan of President $\\times$ Severe Intensity",
                               "Copartisan of President $\\times$ Support Nominee","Outpartisan of President $\\times$ Support Nominee",
                               "Constant"),
          dep.var.labels = "DV: Support for Delay",
          dep.var.caption = "",
          title="Regression Results: Accounting for Support for Nominee",
          label = "individual-analysis-2-for-support",
          keep.stat =  c("n","rsq","f"))

#############
# TABLE D.6 #
#############
# Model 1: basic analysis, no covariates, no interaction, logistic regression
omnibus.regression.logit.1 <- glm(support_delay ~ copartisan_of_president + outpartisan_of_president + intensity, data=omnibus_dataset, family="binomial"(link="logit"), x=T)
summary(omnibus.regression.logit.1)

# Model 2: no covariates, interaction, logistic regression
omnibus.regression.logit.2 <- glm(support_delay ~ copartisan_of_president*intensity + outpartisan_of_president*intensity, data=omnibus_dataset, family="binomial"(link="logit"), x=T)
summary(omnibus.regression.logit.2)

# Model 3: gender and race covariates (available for all surveys), interaction, president fixed effects, logistic regression
omnibus.regression.logit.3 <- glm(support_delay ~ copartisan_of_president*intensity + outpartisan_of_president*intensity + white + male + president, data=omnibus_dataset, family="binomial"(link="logit"), x=T)
summary(omnibus.regression.logit.3)

# Putting the models together and into a stargazer table
logit.regression.models <- list(omnibus.regression.logit.1, omnibus.regression.logit.2, omnibus.regression.logit.3)
stargazer(logit.regression.models, digits=2, star.cutoffs=c(0.05), no.space=T,
          covariate.labels = c("Copartisan of President","Outpartisan of President","White","Male","Obama","Trump",
                               "Copartisan of President $\\times$ Moderate Intensity","Copartisan of President $\\times$ Severe Intensity",
                               "Outpartisan of President $\\times$ Moderate Intensity","Outpartisan of President $\\times$ Severe Intensity",
                               "Moderate Intensity","Severe Intensity",
                               "Constant"),
          dep.var.labels = "DV: Support for Delay",
          dep.var.caption = "",
          title="Logistic Regression Results: Intensity, Partisanship, and Support for Obstruction",
          label = "regression-version-of-analysis-2-logit",
          keep.stat = c("n","AIC","ll"))

#############
# TABLE D.7 #
#############
# Model 1: basic analysis, no covariates, no interaction, leaners as independents
omnibus.regression.1.leaners.independents <- lm(support_delay ~ copartisan_of_president_leaners_as_independents + outpartisan_of_president_leaners_as_independents + intensity, data=omnibus_dataset)
summary(omnibus.regression.1.leaners.independents)

# Model 2: no covariates, interaction, leaners as independents
omnibus.regression.2.leaners.independents <- lm(support_delay ~ copartisan_of_president_leaners_as_independents*intensity + outpartisan_of_president_leaners_as_independents*intensity, data=omnibus_dataset)
summary(omnibus.regression.2.leaners.independents)

# Model 3: gender and race covariates (available for all surveys), interaction, president fixed effects, leaners as independents
omnibus.regression.3.leaners.independents <- lm(support_delay ~ copartisan_of_president_leaners_as_independents*intensity + outpartisan_of_president_leaners_as_independents*intensity + white + male + president, data=omnibus_dataset)
summary(omnibus.regression.3.leaners.independents)

# Putting the models together and into a stargazer table
leaners.as.independents.regression.models <- list(omnibus.regression.1.leaners.independents, omnibus.regression.2.leaners.independents, omnibus.regression.3.leaners.independents)
stargazer(leaners.as.independents.regression.models, digits=2, star.cutoffs=c(0.05), no.space=T,
          covariate.labels = c("Copartisan of President","Outpartisan of President","White","Male","Obama","Trump",
                               "Copartisan of President $\\times$ Moderate Intensity","Copartisan of President $\\times$ Severe Intensity",
                               "Outpartisan of President $\\times$ Moderate Intensity","Outpartisan of President $\\times$ Severe Intensity",
                               "Moderate Intensity","Severe Intensity",
                               "Constant"),
          dep.var.labels = "DV: Support for Delay",
          dep.var.caption = "",
          title="Regression Results: Coding Leaners as Independents",
          label = "regression-version-of-analysis-2-leaners-as-independents",
          keep.stat =  c("n","rsq","f"))

#############
# TABLE D.8 #
#############
# Variable pooling moderate and severe intensity
omnibus_dataset$moderate_severe_intensity <- ifelse(omnibus_dataset$intensity %in% c("moderate","severe"), 1, 0)

# Equivalent of model 2: no covariates, interaction, pooling moderate/severe
omnibus.regression.2.moderate.severe.pooled <- lm(support_delay ~ copartisan_of_president*moderate_severe_intensity + outpartisan_of_president*moderate_severe_intensity, data=omnibus_dataset)
summary(omnibus.regression.2.moderate.severe.pooled)

# Putting the model into a stargazer table
stargazer(omnibus.regression.2.moderate.severe.pooled, digits=2, star.cutoffs=c(0.05), no.space=T,
          covariate.labels = c("Copartisan of President","Moderate/Severe Intensity","Outpartisan of President",
                               "Copartisan of President $\\times$ Moderate/Severe Intensity",
                               "Outpartisan of President $\\times$ Moderate/Severe Intensity",
                               "Constant"),
          dep.var.labels = "DV: Support for Delay",
          dep.var.caption = "",
          title="Regression Results: Pooling Moderate and Severe Intensity",
          label = "individual-analysis-2-pooled-moderate-severe",
          keep.stat =  c("n","rsq","f"))
